<?
namespace Api
{

	require_once 'Smarty/Smarty.class.php';
	/** View
	 * Parent using to create view and layout classes
	 * Automaticaly connected with SMARTY
	**/
	abstract class	View
	{
		////////////////////////////////////
		
		protected $m_params=array();	// Site parameters
		protected $m_smarty=null;		// Smarty class ptr		
		protected $m_config=array();
		////////////////////////////////////
		        
		public function	__construct(array $config, array $params=array())
		{
			$this->m_params = $params;
			$this->m_config = $config;
			
			/** initalize smarty system **/
			if(array_key_exists('LayoutPtr',$config) && $config['LayoutPtr']!=null){
				$this->m_smarty = &$config['LayoutPtr']; 
			}else{
				$this->m_smarty = new \Smarty();	
                if(empty($this->m_smarty->template_dir))		
				    $this->m_smarty->template_dir=BASE_PATH.'/'.$params[\Api\ObjectLoader::C_MODULE].'/view';
                if(empty($this->m_smarty->compile_dir))
				    $this->m_smarty->compile_dir=BASE_PATH.'/'.$params[\Api\ObjectLoader::C_MODULE].'/compiled';
                if(empty($this->m_smarty->plugins_dir))
				    $this->m_smarty->plugins_dir=array(
                    BASE_PATH.'/api/Smarty/plugins',
                    BASE_PATH.'/api/Smarty/framework_plugins','sysplugins');
			}
			$debug = false;
            if(isset($this->m_config['Debug']) && $this->m_config['Debug'])
            {
                $this->m_smarty->clearAllCache();
                $this->m_smarty->clearCompiledTemplate();
                $debug = true;
            }
            $this->m_smarty->assign('DEBUG',$debug);

		}
		
		/** Set
		 * Pass variables to smarty engine
		**/
		public function __set($_var, $val)
		{			
			$this->m_smarty->assign($_var, $val);
		}
		
		
		/** GetSmarty
		 * @ret: Smarty instance object
		 **/
		public function & GetSmarty(){
			return $this->m_smarty;
		}
        
        
        
		/** Display
		 * method should display template or include file to it
		**/		
		abstract public function	display($template=null);	
		
		
		public function __destruct(){}
	}
}
?>